//
//  PayViewController.m
//  DemoProject
//
//  Created by zhl on 2017/2/9.
//  Copyright © 2017年 zhl. All rights reserved.
//

#import "PayViewController.h"
#import "MBProgressHUD.h"
#import "HLMBProgressHUD.h"
#import <Foundation/Foundation.h>
#import "MD5.h"
@interface PayViewController ()<UITableViewDelegate,UITableViewDataSource,JZMSDKPayDelegate>{
}
@property (weak, nonatomic) IBOutlet UITableView *payTableView;
@end
@implementation PayViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    _payTableView.delegate =self;
    _payTableView.dataSource =self;
    _payTableView.tableFooterView =[UIView new];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.parArray.count;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    NSDictionary *dic =[_parArray objectAtIndex:indexPath.row];
    cell.textLabel.text =[dic objectForKey:@"typename"];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    typeof(self)weakself =self;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSDictionary<NSString *,NSString *> * typeItem = [weakself.parArray objectAtIndex:indexPath.item];
        NSString * typeId = [typeItem objectForKey:@"typeid"];
        dispatch_async(dispatch_get_main_queue(), ^{
            [MBProgressHUD showHUDAddedTo:weakself.view animated:YES];
            _tokenModel.payType = typeId;
            _tokenModel.isReturn = YES;
            _tokenModel.controler = weakself;
            _tokenModel.zzApi = @"http://39.107.59.151:8001";
            [JZMPay getToken:_tokenModel returnDelegate:self];
        });
    });
}

- (void)hudHidden{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}

- (void)openAppSuccessed{
    [self hudHidden];
}

- (void)openAppFailer:(NSString *)failer{
    dispatch_async(dispatch_get_main_queue(), ^{
        [self hudHidden];
        [HLMBProgressHUD addMBProgressHUDInView:self.view hudMode:5 hideDelay:1.2 hudDetailText:failer];
    });
}

- (void)jftPayFailure:(NSString *)message{
    [self hudHidden];
        dispatch_async(dispatch_get_main_queue(), ^{
            [HLMBProgressHUD addMBProgressHUDInView:self.view hudMode:5 hideDelay:1.2 hudDetailText:message];
        });
}

- (void)jftPayResult:(NSString *)result{
    NSLog(@"---result=%@---",result);
    __weak typeof(self)weakSelf =self;
    dispatch_async(dispatch_get_main_queue(), ^{
        [weakSelf.navigationController popViewControllerAnimated:YES];
         [HLMBProgressHUD addMBProgressHUDInView:[UIApplication sharedApplication].keyWindow hudMode:5 hideDelay:1.2 hudDetailText:result];
    });
}

- (void)jftPaySuccess{

}

@end
